package UIComponents.Messages
{
	import flash.display.Bitmap;
	import flash.display.Loader;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.net.URLRequest;
	import flash.system.Security;

	/**
	 * 消息类 
	 * @author 邓坚
	 * 
	 */
	public class UseMessage
	{
		public var ztId:uint;
		public var ztMessageType:uint;         //消息类型 //显示型 0全部，1礼物，2求赠，3互动，付费   消息类型（3为消费，4为互动，5为求赠，1为礼物）
		public var Content:String;				//消息内容
		public var ztFriendName:String;		//用户名
		public var ztMessageTime:Date;			//时间日期
		public var ztFriendPic:String;			//头像图片
		public var ztStatus:Boolean;           //是否已读	false已读
		
//		public var friend_id:uint;				//好友id
		public var ztCommand:uint;				//命令号id
		public var ztItemId:uint;				//物品ID 1 表示为金币 2 表示为欧币
		public var ztItemCount:uint			//物品数量
		
		public var ztUsePicSp:Sprite;

		private var imgLoader:Loader;
		public function UseMessage(content:String="",ztFriendName:String="",ztMessageTime:Date=null,ztMessageType:uint=1,ztStatus:Boolean=false,ztFriendPic:String="",ztId:uint=0)
		{
			this.ztId      				= 	ztId;
			this.ztMessageType    		= 	ztMessageType;
			this.Content			    = 	content;
			this.ztFriendName			=	ztFriendName;
			this.ztMessageTime			=	ztMessageTime;
			this.ztFriendPic			=	ztFriendPic;
			this.ztStatus				=	ztStatus;
			this.ztCommand				=	ztCommand;
			this.ztItemId				=	ztItemId;
			this.ztItemCount			=	ztItemCount;
			
			this.ztUsePicSp		=	new Sprite();
			
			if(this.ztMessageType==3)
			{
				this.ztUsePicSp.addChild(new xtPic());
				this.ztUsePicSp.x	=	8;
				this.ztUsePicSp.y  	=	15;
			}
			else{
				if(this.ztFriendPic==""){
					this.ztUsePicSp.addChild(new wjPic());
					this.ztUsePicSp.x	=	8;
					this.ztUsePicSp.y  	=	15;
				}
				else{
					imgLoader=new Loader();
					Security.allowDomain("*");
					//			if(ztFriendPic=="") return;
					var urlReq:URLRequest=new URLRequest(this.ztFriendPic);
					imgLoader.load(urlReq);
					imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHanlder);
					
					
				}
			}
		}
		
		private function completeHanlder(evt:Event):void
		{
			imgLoader.contentLoaderInfo.removeEventListener(Event.COMPLETE,completeHanlder);
			this.ztUsePicSp.addChild( Bitmap(imgLoader.content));
			this.ztUsePicSp.width 	=	 50;
			this.ztUsePicSp.height	=	 50;
			
		}
		
		public function get messageTime():Number
		{
			return this.ztMessageTime.time;
		}
	}
}